#
#   api_vcard.py
#
#   David Janes
#   2009.01.31
#
#	Copyright 2008, 2009 David Janes
#
#	Interface to vCards
#

import os
import os
import sys
import types
import pprint
import types
import time

import bm_extract
import api
import vcard
import hcard

from bm_log import Log

class VCardWriter(api.APIBase):
	def Produce(self):
		results = []
		for itemd in self.IterItems():
			mfd = vcard.compose(itemd)
			try:
				results.append(vcard.as_vcard(mfd))
			except:
				Log("ignoring exception", exception = True, verbose = True)

		return	"\n".join(results)

	def IterItems(self):
		for item in self._request_items or []:
			for key, hd in item.iteritems():
				if not key.startswith("hcard:"):
					continue

				yield hd
